﻿@using StackExchange.Opserver.Data.SQL
@model IEnumerable<SQLInstance.DatabaseColumn>
@{
    var columns = Model;
}
<div class="panel panel-default">
    <div class="panel-body">
        <table class="table-striped col-xs-12">
            <thead>
                <tr>
                    <th>Column</th>
                    <th>Constraint</th>
                    <th>Target</th>
                </tr>
            </thead>
            <tbody>
            @foreach (var c in columns.OrderBy(c => c.Position))
            {
                <tr data-id="@c.Id">
                    <td>
                        @if (c.PrimaryKeyConstraint.HasValue())
                        {
                            <i class="fa fa-key fa-fw text-warning" aria-hidden="true" title="Primary Key: @c.PrimaryKeyConstraint"></i>
                        }
                        else if (c.ForeignKeyConstraint.HasValue())
                        {
                            <i class="fa fa-link fa-fw text-primary" aria-hidden="true" title="Foreign Key: @c.ForeignKeyConstraint"></i>
                        }
                        else
                        {
                            <i class="fa fa-list-alt fa-fw text-muted" aria-hidden="true"></i>
                        }
                        @c.ColumnName <span class="text-muted">(@c.DataTypeDescription)</span>
                    </td>
                    <td>@(c.PrimaryKeyConstraint ?? c.ForeignKeyConstraint)</td>
                    <td>
                        @if (c.ForeignKeyConstraint.HasValue())
                        {
                            @:<span class="text-muted">@c.ForeignKeyTargetSchema.</span>@(c.ForeignKeyTargetTable).@(c.ForeignKeyTargetColumn)
                        }
                    </td>
                </tr>
            }
            </tbody>
        </table>
    </div>
</div>